<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        session('[start]');
        $this->display();
    }

    //生成验证码
    public function verify()
    {
        // 实例化Verify对象
        $verify = new \Think\Verify();

        // 配置验证码参数
        $verify->fontSize = 14;     // 验证码字体大小
        $verify->length = 4;        // 验证码位数
        $verify->imageH = 34;       // 验证码高度
        $verify->useImgBg = true;   // 开启验证码背景
        $verify->useNoise = false;  // 关闭验证码干扰杂点
        $verify->entry();
    }

    //登陆校验校验
    public function checkLogin()
    {
        $verify = new \Think\Verify();
        $code = I('post.verify');//表单验证码

        $uname = I('post.username');//表单登录名
        $pwd = md5(I('post.password'));//表单密码


       //系统管理员登陆

        $systemAdmin = M('admin');

            //判断密码正确性
        $systemAdminInfo = $systemAdmin->where("ad_name='%s'",$uname)->select();
        $truePwd = $systemAdminInfo['0']['ad_pwd'];
//           dump($truePwd);
        if($truePwd != $pwd){
                $this->error('密码错误');
            }

            //记录session
            $systemAdminId = $systemAdminInfo['0']['ad_id'];
            session('systemAdminId',$systemAdminId);


        //校验验证码
        if ($verify->check($code)) {
            session('flag','true');
            $this->success('登陆成功','../Question/questionList',3);
        } else {
            $this->error('验证码错误');
        }
    }

    //退出登录
    public function doLogOut(){
        session('[destroy]');
        redirect('../Index/index',1,'您已注销！');
    }






}